package com.hh.m15e.component;

import com.hh.m15e.domain.Input6201;
import com.hh.m15e.domain.ProMyfbyYbDjfycx;
import com.hh.m15e.domain.SpYhwx2Ybxdcx;
import com.hh.m15e.service.IProMyfbyYbDjfycxService;
import com.hh.m15e.service.ISpYhwx2YbxdcxService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 作者: Ⅹ玖
 * 创建日期：2025/2/19 13:31
 * 文档描述：封装存储过程调用
 */
@Component
public class Param6201Util {
    @Autowired
    private ISpYhwx2YbxdcxService spYhwx2YbxdcxService;
    @Autowired
    private IProMyfbyYbDjfycxService proMyfbyYbDjfycxService;

    /**
     * 获取参数6201接口所需入参
     * @param param 字符串
     * @return Input6201
     */
    public Input6201 getParam6201(String param){

        SpYhwx2Ybxdcx spYhwx2Ybxdcx = getSpYhwx2Ybxdcx(param);
        if(!("1".equals(spYhwx2Ybxdcx.getFirstMedicalResponse().getCode()) || "成功".equals(spYhwx2Ybxdcx.getFirstMedicalResponse().getMessage()))) return null;
        // 封装第二个存储过程所需参数
        HashMap<String, String> map = new HashMap<>();
        map.put("appId",spYhwx2Ybxdcx.getFirstMedicalResponse().getAppId());
        map.put("orgCodg",spYhwx2Ybxdcx.getFirstMedicalResponse().getOrgCodg());
        map.put("medOrgOrd",spYhwx2Ybxdcx.getSecondMedicalResponse().getMedOrgOrd());

        ProMyfbyYbDjfycx proMyfbyYbDjfycx = getProMyfbyYbDjfycx(map);
        if(!("1".equals(proMyfbyYbDjfycx.getStatusCode().getCode()) || "成功".equals(proMyfbyYbDjfycx.getStatusCode().getMessage()))) return null;
        Input6201 input6201 = proMyfbyYbDjfycx.getInput6201();
        input6201.setFeeDetailList(proMyfbyYbDjfycx.getFeedetailList());
        input6201.setDiseinfoList(proMyfbyYbDjfycx.getDiseinfoList());

        return input6201;
    }
    /**
     * 获取sp_yhwx2_ybxdcx存储过程数据
     * @param params 字符串
     * @return SpYhwx2Ybxdcx
     */
    private SpYhwx2Ybxdcx getSpYhwx2Ybxdcx(String params){
        return spYhwx2YbxdcxService.getSpYhwx2Ybxdcx(params);
    }

    /**
     * 获取pro_myfby_yb_djfycx存储过程数据
     * @param params Map集合
     * @return ProMyfbyYbDjfycx
     */
    private ProMyfbyYbDjfycx getProMyfbyYbDjfycx(Map<String,String> params){
        return proMyfbyYbDjfycxService.callProMyfbyYbDjfycx(params);
    }


}
